home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / MPW Interfaces / CIncludes / Sound.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  13.9 KB  |  508 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Sound.h
  3.  
  4.     Copyright:    © 1983-1993 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Version:    System 7.1 for ETO #11
  8.     Created:    Tuesday, March 30, 1993 18:00
  9.  
  10. */
  11.  
  12. #ifndef __SOUND__
  13. #define __SOUND__
  14.  
  15. #ifndef __TYPES__
  16. #include <Types.h>
  17. #endif
  18.  
  19. #ifndef __FILES__
  20. #include <Files.h>
  21. #endif
  22.  
  23.  
  24. enum {
  25.  
  26.  swMode = -1,                                /* Sound Driver modes */
  27.  ftMode = 1,
  28.  ffMode = 0,
  29.  
  30.  
  31. #define synthCodeRsrc 'snth'                /* Resource types used by Sound Manager */
  32. #define soundListRsrc 'snd '
  33.  
  34. #define twelfthRootTwo 1.05946309434
  35.  
  36.  rate22khz = 0x56EE8BA3,                    /* 22254.54545 in fixed-point */
  37.  rate11khz = 0x2B7745D1,                    /* 11127.27273 in fixed-point */
  38.  
  39. /* synthesizer numbers for SndNewChannel */
  40.  squareWaveSynth = 1,                        /*square wave synthesizer*/
  41.  waveTableSynth = 3,                        /*wave table synthesizer*/
  42.  sampledSynth = 5,                            /*sampled sound synthesizer*/
  43.  
  44. /* old Sound Manager MACE synthesizer numbers */
  45.  MACE3snthID = 11,
  46.  MACE6snthID = 13,
  47.  
  48. /* command numbers for SndDoCommand and SndDoImmediate */
  49.  nullCmd = 0,
  50.  initCmd = 1,
  51.  freeCmd = 2,
  52.  quietCmd = 3,
  53.  flushCmd = 4,
  54.  reInitCmd = 5,
  55.  
  56.  waitCmd = 10,
  57.  pauseCmd = 11,
  58.  resumeCmd = 12,
  59.  callBackCmd = 13
  60. };
  61. enum {
  62.  syncCmd = 14,
  63.  emptyCmd = 15,
  64.  
  65.  tickleCmd = 20,
  66.  requestNextCmd = 21,
  67.  howOftenCmd = 22,
  68.  wakeUpCmd = 23,
  69.  availableCmd = 24,
  70.  versionCmd = 25,
  71.  totalLoadCmd = 26,
  72.  loadCmd = 27,
  73.  
  74.  scaleCmd = 30,
  75.  tempoCmd = 31,
  76.  
  77.  freqDurationCmd = 40,
  78.  restCmd = 41,
  79.  freqCmd = 42,
  80.  ampCmd = 43,
  81.  timbreCmd = 44,
  82.  getAmpCmd = 45,
  83.  
  84.  waveTableCmd = 60,
  85.  phaseCmd = 61
  86. };
  87. enum {
  88.  
  89.  soundCmd = 80,
  90.  bufferCmd = 81,
  91.  rateCmd = 82,
  92.  continueCmd = 83,
  93.  doubleBufferCmd = 84,
  94.  getRateCmd = 85,
  95.  
  96.  sizeCmd = 90,
  97.  convertCmd = 91,
  98.  
  99.  stdQLength = 128,
  100.  dataOffsetFlag = 0x8000,
  101.  
  102.  waveInitChannelMask = 0x07,
  103.  waveInitChannel0 = 0x04,
  104.  waveInitChannel1 = 0x05,
  105.  waveInitChannel2 = 0x06,
  106.  waveInitChannel3 = 0x07,
  107.  
  108. /* channel initialization parameters */
  109.  initPanMask = 0x0003,                        /* mask for right/left pan values */
  110.  initSRateMask = 0x0030,                    /* mask for sample rate values */
  111.  initStereoMask = 0x00C0,                    /* mask for mono/stereo values */
  112.  initCompMask = 0xFF00,                        /* mask for compression IDs */
  113.  
  114.  initChanLeft = 0x0002                        /* left stereo channel */
  115. };
  116. enum {
  117.  initChanRight = 0x0003,                    /* right stereo channel */
  118.  initNoInterp = 0x0004,                        /* no linear interpolation */
  119.  initNoDrop = 0x0008,                        /* no drop-sample conversion */
  120.  initMono = 0x0080,                            /* monophonic channel */
  121.  initStereo = 0x00C0,                        /* stereo channel */
  122.  initMACE3 = 0x0300,                        /* MACE 3:1 */
  123.  initMACE6 = 0x0400,                        /* MACE 6:1 */
  124.  
  125.  initChan0 = 0x0004,                        /* channel 0 - wave table only */
  126.  initChan1 = 0x0005,                        /* channel 1 - wave table only */
  127.  initChan2 = 0x0006,                        /* channel 2 - wave table only */
  128.  initChan3 = 0x0007,                        /* channel 3 - wave table only */
  129.  
  130.  stdSH = 0x00,                                /* Standard sound header encode value */
  131.  extSH = 0xFF,                                /* Extended sound header encode value */
  132.  cmpSH = 0xFE,                                /* Compressed sound header encode value */
  133.  
  134.  notCompressed = 0,                            /* compression ID's */
  135.  twoToOne = 1,
  136.  eightToThree = 2,
  137.  threeToOne = 3,
  138.  sixToOne = 4,
  139.  
  140.  outsideCmpSH = 0                            /* MACE constants */
  141. };
  142. enum {
  143.  insideCmpSH = 1,
  144.  aceSuccess = 0,
  145.  aceMemFull = 1,
  146.  aceNilBlock = 2,
  147.  aceBadComp = 3,
  148.  aceBadEncode = 4,
  149.  aceBadDest = 5,
  150.  aceBadCmd = 6,
  151.  sixToOnePacketSize = 8,
  152.  threeToOnePacketSize = 16,
  153.  stateBlockSize = 64,
  154.  leftOverBlockSize = 32,
  155.  
  156.  firstSoundFormat = 0x0001,                    /* general sound format */
  157.  secondSoundFormat = 0x0002,                /* special sampled sound format (HyperCard) */
  158.  
  159.  dbBufferReady = 0x00000001,                /* double buffer is filled */
  160.  dbLastBuffer = 0x00000004,                    /* last double buffer to play */
  161.  
  162.  sysBeepDisable = 0x0000,                    /* SysBeep() enable flags */
  163.  sysBeepEnable = 0x0001,
  164.  
  165.  unitTypeNoSelection = 0xFFFF,                /* unitTypes for AudioSelection.unitType */
  166.  unitTypeSeconds = 0x0000
  167. };
  168.  
  169.  
  170. /*   Structures for Sound Driver   */
  171.  
  172.  
  173. typedef unsigned char FreeWave[30001];
  174.  
  175. struct FFSynthRec {
  176.  short mode;
  177.  Fixed count;
  178.  FreeWave waveBytes;
  179. };
  180.  
  181. typedef struct FFSynthRec FFSynthRec;
  182. typedef FFSynthRec *FFSynthPtr;
  183.  
  184. struct Tone {
  185.  short count;
  186.  short amplitude;
  187.  short duration;
  188. };
  189.  
  190. typedef struct Tone Tone;
  191.  
  192.  
  193. typedef Tone Tones[5001];
  194.  
  195. struct SWSynthRec {
  196.  short mode;
  197.  Tones triplets;
  198. };
  199.  
  200. typedef struct SWSynthRec SWSynthRec;
  201. typedef SWSynthRec *SWSynthPtr;
  202.  
  203.  
  204. typedef unsigned char Wave[256];
  205. typedef Wave *WavePtr;
  206.  
  207. struct FTSoundRec {
  208.  short duration;
  209.  Fixed sound1Rate;
  210.  long sound1Phase;
  211.  Fixed sound2Rate;
  212.  long sound2Phase;
  213.  Fixed sound3Rate;
  214.  long sound3Phase;
  215.  Fixed sound4Rate;
  216.  long sound4Phase;
  217.  WavePtr sound1Wave;
  218.  WavePtr sound2Wave;
  219.  WavePtr sound3Wave;
  220.  WavePtr sound4Wave;
  221. };
  222.  
  223. typedef struct FTSoundRec FTSoundRec;
  224. typedef FTSoundRec *FTSndRecPtr;
  225.  
  226. struct FTSynthRec {
  227.  short mode;
  228.  FTSndRecPtr sndRec;
  229. };
  230.  
  231. typedef struct FTSynthRec FTSynthRec;
  232. typedef FTSynthRec *FTSynthPtr;
  233.  
  234.  
  235. typedef pascal void (*SndCompletionProcPtr)(void);
  236.  
  237. /*   Structures for Sound Manager   */
  238.  
  239. struct SndCommand {
  240.  unsigned short cmd;
  241.  short param1;
  242.  long param2;
  243. };
  244.  
  245. typedef struct SndCommand SndCommand;
  246.  
  247.  
  248. typedef long Time;                            /* in half milliseconds */
  249.  
  250.  
  251.  
  252. typedef struct SndChannel SndChannel;
  253. typedef SndChannel *SndChannelPtr;
  254.  
  255.  
  256. typedef pascal void (*SndCallBackProcPtr)(SndChannelPtr chan, SndCommand cmd);
  257.  
  258. struct SndChannel {
  259.     struct SndChannel *nextChan;
  260.     Ptr firstMod;                              /* reserved for the Sound Manager */
  261.     SndCallBackProcPtr callBack;
  262.     long userInfo;
  263.     Time wait;                                 /* The following is for internal Sound Manager use only.*/
  264.     SndCommand cmdInProgress;
  265.     short flags;
  266.     short qLength;
  267.     short qHead;                               /* next spot to read or -1 if empty */
  268.     short qTail;                               /* next spot to write = qHead if full */
  269.     SndCommand queue[stdQLength];
  270. };
  271.  
  272. /* MACE structures */
  273. struct StateBlock {
  274.  short stateVar[stateBlockSize];
  275. };
  276.  
  277. typedef struct StateBlock StateBlock;
  278. typedef StateBlock *StateBlockPtr;
  279.  
  280. struct LeftOverBlock {
  281.  unsigned long count;
  282.  char sampleArea[leftOverBlockSize];
  283. };
  284.  
  285. typedef struct LeftOverBlock LeftOverBlock;
  286. typedef LeftOverBlock *LeftOverBlockPtr;
  287.  
  288. struct ModRef {
  289.  unsigned short modNumber;
  290.  long modInit;
  291. };
  292.  
  293. typedef struct ModRef ModRef;
  294.  
  295. struct SndListResource {
  296.  short format;
  297.  short numModifiers;
  298.  ModRef modifierPart[1];                    /*This is a variable length array*/
  299.  short numCommands;
  300.  SndCommand commandPart[1];                    /*This is a variable length array*/
  301.  char dataPart[1];                            /*This is a variable length array*/
  302. };
  303.  
  304. typedef struct SndListResource SndListResource;
  305. typedef SndListResource *SndListPtr;
  306.  
  307. struct SoundHeader {
  308.  Ptr samplePtr;                                /* if NIL then samples are in sampleArea */
  309.  unsigned long length;                        /* length of sound in bytes */
  310.  Fixed sampleRate;                            /* sample rate for this sound */
  311.  unsigned long loopStart;                    /* start of looping portion */
  312.  unsigned long loopEnd;                        /* end of looping portion */
  313.  unsigned char encode;                        /* header encoding */
  314.  unsigned char baseFrequency;                /* baseFrequency value */
  315.  char sampleArea[1];
  316. };
  317.  
  318. typedef struct SoundHeader SoundHeader;
  319. typedef SoundHeader *SoundHeaderPtr;
  320.  
  321. struct CmpSoundHeader {
  322.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  323.  unsigned long numChannels;                    /* number of channels i.e. mono = 1 */
  324.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  325.  unsigned long loopStart;                    /* loopStart of sound before compression */
  326.  unsigned long loopEnd;                        /* loopEnd of sound before compression */
  327.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  328.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  329.  unsigned long numFrames;                    /* length in frames ( packetFrames or sampleFrames ) */
  330.  extended80 AIFFSampleRate;                    /* IEEE sample rate */
  331.  Ptr markerChunk;                            /* sync track */
  332.  Ptr futureUse1;                            /* reserved by Apple */
  333.  Ptr futureUse2;                            /* reserved by Apple */
  334.  StateBlockPtr stateVars;                    /* pointer to State Block */
  335.  LeftOverBlockPtr leftOverSamples;            /* used to save truncated samples between compression calls */
  336.  unsigned short compressionID;                /* 0 means no compression, non zero means compressionID */
  337.  unsigned short packetSize;                    /* number of bits in compressed sample packet */
  338.  unsigned short snthID;                        /* resource ID of Sound Manager snth that contains NRT C/E */
  339.  unsigned short sampleSize;                    /* number of bits in non-compressed sample */
  340.  char sampleArea[1];                        /* space for when samples follow directly */
  341. };
  342.  
  343. typedef struct CmpSoundHeader CmpSoundHeader;
  344. typedef CmpSoundHeader *CmpSoundHeaderPtr;
  345.  
  346. struct ExtSoundHeader {
  347.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  348.  unsigned long numChannels;                    /* number of channels,  ie mono = 1 */
  349.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  350.  unsigned long loopStart;                    /* same meaning as regular SoundHeader */
  351.  unsigned long loopEnd;                        /* same meaning as regular SoundHeader */
  352.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  353.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  354.  unsigned long numFrames;                    /* length in total number of frames */
  355.  extended80 AIFFSampleRate;                    /* IEEE sample rate */
  356.  Ptr markerChunk;                            /* sync track */
  357.  Ptr instrumentChunks;                        /* AIFF instrument chunks */
  358.  Ptr AESRecording;
  359.  unsigned short sampleSize;                    /* number of bits in sample */
  360.  unsigned short futureUse1;                    /* reserved by Apple */
  361.  unsigned long futureUse2;                    /* reserved by Apple */
  362.  unsigned long futureUse3;                    /* reserved by Apple */
  363.  unsigned long futureUse4;                    /* reserved by Apple */
  364.  char sampleArea[1];                        /* space for when samples follow directly */
  365. };
  366.  
  367. typedef struct ExtSoundHeader ExtSoundHeader;
  368. typedef ExtSoundHeader *ExtSoundHeaderPtr;
  369.  
  370. struct ConversionBlock {
  371.  short destination;
  372.  short unused;
  373.  CmpSoundHeaderPtr inputPtr;
  374.  CmpSoundHeaderPtr outputPtr;
  375. };
  376.  
  377. typedef struct ConversionBlock ConversionBlock;
  378. typedef ConversionBlock *ConversionBlockPtr;
  379.  
  380. struct SMStatus {
  381.  short smMaxCPULoad;
  382.  short smNumChannels;
  383.  short smCurCPULoad;
  384. };
  385.  
  386. typedef struct SMStatus SMStatus;
  387. typedef SMStatus *SMStatusPtr;
  388.  
  389. struct SCStatus {
  390.  Fixed scStartTime;
  391.  Fixed scEndTime;
  392.  Fixed scCurrentTime;
  393.  Boolean scChannelBusy;
  394.  Boolean scChannelDisposed;
  395.  Boolean scChannelPaused;
  396.  Boolean scUnused;
  397.  unsigned long scChannelAttributes;
  398.  long scCPULoad;
  399. };
  400.  
  401. typedef struct SCStatus SCStatus;
  402. typedef SCStatus *SCStatusPtr;
  403.  
  404. struct AudioSelection {
  405.  long unitType;
  406.  Fixed selStart;
  407.  Fixed selEnd;
  408. };
  409.  
  410. typedef struct AudioSelection AudioSelection;
  411. typedef AudioSelection *AudioSelectionPtr;
  412.  
  413. struct SndDoubleBuffer {
  414.  long dbNumFrames;
  415.  long dbFlags;
  416.  long dbUserInfo[2];
  417.  char dbSoundData[1];
  418. };
  419.  
  420. typedef struct SndDoubleBuffer SndDoubleBuffer;
  421. typedef SndDoubleBuffer *SndDoubleBufferPtr;
  422.  
  423.  
  424. typedef pascal void (*SndDoubleBackProcPtr) (SndChannelPtr channel,
  425.            SndDoubleBufferPtr doubleBufferPtr);
  426.  
  427. struct SndDoubleBufferHeader {
  428.  short dbhNumChannels;
  429.  short dbhSampleSize;
  430.  short dbhCompressionID;
  431.  short dbhPacketSize;
  432.  Fixed dbhSampleRate;
  433.  SndDoubleBufferPtr dbhBufferPtr[2];
  434.  SndDoubleBackProcPtr dbhDoubleBack;
  435. };
  436.  
  437. typedef struct SndDoubleBufferHeader SndDoubleBufferHeader;
  438. typedef SndDoubleBufferHeader *SndDoubleBufferHeaderPtr;
  439.  
  440.  
  441. #ifdef __cplusplus
  442. extern "C" {
  443. #endif
  444. pascal OSErr SndDoCommand(SndChannelPtr chan,const SndCommand *cmd,Boolean noWait)
  445.  = 0xA803; 
  446. pascal OSErr SndDoImmediate(SndChannelPtr chan,const SndCommand *cmd)
  447.  = 0xA804; 
  448. pascal OSErr SndNewChannel(SndChannelPtr *chan,short synth,long init,SndCallBackProcPtr userRoutine)
  449.  = 0xA807; 
  450. pascal OSErr SndDisposeChannel(SndChannelPtr chan,Boolean quietNow)
  451.  = 0xA801; 
  452. pascal OSErr SndPlay(SndChannelPtr chan,Handle sndHdl,Boolean async)
  453.  = 0xA805; 
  454. pascal OSErr SndAddModifier(SndChannelPtr chan,ProcPtr modifier,short id,
  455.  long init)
  456.  = 0xA802; 
  457. pascal OSErr SndControl(short id,SndCommand *cmd)
  458.  = 0xA806; 
  459.  
  460. pascal void SetSoundVol(short level); 
  461. #pragma parameter GetSoundVol(__A0)
  462. pascal void GetSoundVol(short *level)
  463.  = {0x4218,0x10B8,0x0260}; 
  464. pascal void StartSound(const void *synthRec,long numBytes,SndCompletionProcPtr completionRtn); 
  465. pascal void StopSound(void); 
  466. pascal Boolean SoundDone(void); 
  467.  
  468. pascal NumVersion SndSoundManagerVersion(void)
  469.  = {0x203C,0x000C,0x0008,0xA800}; 
  470. pascal OSErr SndStartFilePlay(SndChannelPtr chan,short fRefNum,short resNum,
  471.  long bufferSize,void *theBuffer,AudioSelectionPtr theSelection,ProcPtr theCompletion,
  472.  Boolean async)
  473.  = {0x203C,0x0D00,0x0008,0xA800}; 
  474. pascal OSErr SndPauseFilePlay(SndChannelPtr chan)
  475.  = {0x203C,0x0204,0x0008,0xA800}; 
  476. pascal OSErr SndStopFilePlay(SndChannelPtr chan,Boolean async)
  477.  = {0x203C,0x0308,0x0008,0xA800}; 
  478. pascal OSErr SndChannelStatus(SndChannelPtr chan,short theLength,SCStatusPtr theStatus)
  479.  = {0x203C,0x0010,0x0008,0xA800}; 
  480. pascal OSErr SndManagerStatus(short theLength,SMStatusPtr theStatus)
  481.  = {0x203C,0x0014,0x0008,0xA800}; 
  482. pascal void SndGetSysBeepState(short *sysBeepState)
  483.  = {0x203C,0x0018,0x0008,0xA800}; 
  484. pascal OSErr SndSetSysBeepState(short sysBeepState)
  485.  = {0x203C,0x001C,0x0008,0xA800}; 
  486. pascal OSErr SndPlayDoubleBuffer(SndChannelPtr chan,SndDoubleBufferHeaderPtr theParams)
  487.  = {0x203C,0x0020,0x0008,0xA800}; 
  488.  
  489. pascal NumVersion MACEVersion(void)
  490.  = {0x203C,0x0000,0x0010,0xA800}; 
  491. pascal void Comp3to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  492.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  493.  = {0x203C,0x0004,0x0010,0xA800}; 
  494. pascal void Exp1to3(const void *inBuffer,void *outBuffer,unsigned long cnt,
  495.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  496.  = {0x203C,0x0008,0x0010,0xA800}; 
  497. pascal void Comp6to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  498.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  499.  = {0x203C,0x000C,0x0010,0xA800}; 
  500. pascal void Exp1to6(const void *inBuffer,void *outBuffer,unsigned long cnt,
  501.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  502.  = {0x203C,0x0010,0x0010,0xA800}; 
  503. #ifdef __cplusplus
  504. }
  505. #endif
  506.  
  507. #endif
  508.